package com.redis.config;

import com.redis.enty.OrderInfo;


import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;


@Slf4j
@Component
public class SendMessage {

    @Autowired
    RabbitTemplate rabbitTemplate;

    public void sendMqMsg(OrderInfo orderInfo, String topicExchange, String routingKey) {
        rabbitTemplate.convertAndSend(topicExchange, routingKey, orderInfo);
    }

    public void sendMsg(String  delayedExchange ,String routingKey, String message,Integer delayTime) {
        log.info("当前时间：{},发送时长{}信息给延迟队列：{}", new Date().toString(), delayTime, message);
        rabbitTemplate.convertAndSend(delayedExchange, routingKey, message, msg -> {
            //设置发送消息的延长时间 单位：ms
            msg.getMessageProperties().setDelay(delayTime);
            return msg;
        });
    }



}
